using System;
using UnityEngine;

[Serializable]
[AddComponentMenu("Camera-Control/Smooth Follow")]
public class SmoothFollow : MonoBehaviour
{
	private int state;

	public Transform targetpos;

	public Transform playerpos;

	public float rdistance;

	public Transform target;

	public float height;

	public float heightDamping;

	public Transform tr;

	public float wantedHeight;

	public int tilt;

	public SmoothFollow()
	{
		state = 1;
		height = 5f;
		heightDamping = 2f;
		wantedHeight = 3.2f;
	}

	public void Start()
	{
		StateManager.heightLimit = 3;
		tr = transform;
		targetpos = GameObject.Find("knight dranzerAI").transform;
		playerpos = GameObject.Find("knight dranzer").transform;
		tilt = 1;
		float x = 0.76f;
		Quaternion rotation = tr.rotation;
		rotation.x = x;
		Quaternion quaternion2 = tr.rotation = rotation;
		int num = 0;
		Quaternion rotation2 = tr.rotation;
		rotation2.z = num;
		Quaternion quaternion4 = tr.rotation = rotation2;
		int num2 = 0;
		Quaternion rotation3 = tr.rotation;
		rotation3.y = num2;
		Quaternion quaternion6 = tr.rotation = rotation3;
	}

	public void LateUpdate()
	{
		Vector3 position = tr.position;
		float y = position.y;
		Transform transform = tr;
		Vector3 position2 = tr.position;
		Vector3 position3 = target.position;
		float x = position3.x;
		float y2 = Mathf.Lerp(y, wantedHeight, 50f * Time.deltaTime);
		Vector3 position4 = target.position;
		transform.position = Vector3.Lerp(position2, new Vector3(x, y2, position4.z - (float)tilt), 4f * Time.deltaTime);
	}

	public void checkstate()
	{
		if ((bool)targetpos && (bool)playerpos)
		{
			height = rdistance + 2f;
			rdistance = Vector3.Magnitude(playerpos.position - targetpos.position);
			Vector3 position = target.position;
			wantedHeight = Mathf.Clamp(position.y + height, StateManager.heightLimit, 20f);
		}
	}

	public void checkstart()
	{
		wantedHeight = 3.2f;
	}

	public void Main()
	{
		InvokeRepeating("checkstate", 5.5f, 0.14f);
		Invoke("checkstart", 0f);
	}
}
